package com.iemes.controller.warehouse;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.ProductreturnFormMap;
import com.iemes.mapper.warehouse.ProductreturnMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/returnproduct_outreceipt_form/")
@Controller
public class ReturnproductOutreceipt_FormController extends BaseController {
	
	@Inject
	private ProductreturnMapper productreturnMapper;

	// 查看根据出仓单新增退货产品，显示按钮。
	@RequestMapping("returnproduct_outreceipt_all")
	public String returnproduct_outreceipt_form(Model model) {
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/warehouse/returnproduct_outreceipt_list";
	}

	// 根据出仓单新增退货产品分页
	@ResponseBody
	@RequestMapping("returnproduct_outreceipt_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception {
		ProductreturnFormMap productreturnFormMap=getFormMap(ProductreturnFormMap.class);
		List<Map<String, Object>> productreturn=productreturnMapper.getAll(productreturnFormMap);
		LuogicPaging(pageNow, pageSize, productreturn);
		return pageView;
	}

	// 编辑根据出仓单新增退货产品
	@RequestMapping("returnproduct_outreceipt_form_edit")
	public String editUI(Model model) throws Exception {
		String id = getPara("id");
		if(Common.isNotEmpty(id)){
			//根据id获得根据出仓单新增退货产品
			ProductreturnFormMap productreturn=productreturnMapper.getById(id);
			model.addAttribute("productreturn",productreturn);
		}
		return Common.BACKGROUND_PATH + "/warehouse/returnproduct_outreceipt_form_edit";
	}

	// 修改根据出仓单新增退货产品
	@ResponseBody
	@RequestMapping(value = "returnproduct_outreceipt_form_editEntity")
	@Transactional(readOnly=false)//需要事务操作必须加入此注解
	@SystemLog(module = "根据出仓单新增退货产品", methods = "查看根据出仓单新增退货产品-修改根据出仓单新增退货产品") // 凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity() throws Exception {
		ProductreturnFormMap productreturnFormMap = getFormMap(ProductreturnFormMap.class);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		productreturnFormMap.put("date", sdf.format(date));
		productreturnFormMap.put("status", 1);
		productreturnFormMap.put("statisticsDate", "");
		baseMapper.editEntity(productreturnFormMap);
		return "success";
	}	
}












